/*
 * @Description: 
 * @Author: Zhang_xx
 * @Date: 2025-03-26 17:51:30
 * @LastEditors: Zhang_xx
 * @LastEditTime: 2025-03-27 16:58:55
 */
const koa = require('koa')
const Router = require('koa-router')
const mockList = require('./mock/index')

const app = new koa()
const router = new Router()

// 模拟真实接口请求 【反应时间】
async function getRes (fn) {
  return new Promise(ressolve => {
    setTimeout (() => {
    const res = fn()
      ressolve(res)
    },1000)
  })
}

// 注册mock路由
mockList.forEach(item => {
  const { url, method, response } = item
  router[method](url, async ctx => {
    // const res = response()
    const res = await getRes(response)
    ctx.body = res
  })
})

app.use(router.routes())
app.listen(3000)   // port窗口